<template>
  <svg v-if="iconType === 'svg'" :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
  <StringToSub v-else :icon_class="props.iconClass" :class="svgClass"></StringToSub>
</template>
<script lang="ts" setup name="SvgIcon">
import StringToSub from './StringToSub'
interface SvgType {
  iconClass: string
  iconType?: 'svg' | 'element'
  className?: string
}
// 默认值
const props: SvgType = withDefaults(defineProps<SvgType>(), {
  iconType: 'svg',
  className: ''
})
const iconName = computed(() => `#icon-${props.iconClass}`)
const svgClass = computed(() => {
  if (props.className) {
    return `svg-icon ${props.className}`
  }
  return 'svg-icon'
})
</script>

<style scope lang="scss">
.sub-el-icon,
.nav-icon {
  display: inline-block;
  font-size: 17px;
  margin-right: 12px;
  position: relative;
}
.svg-icon {
  width: 1em;
  height: 1em;
  font-size: 17px;
  margin-bottom: 1px;
  position: relative;
  fill: currentColor;
  vertical-align: -2px;
}
</style>
